using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using T2.Logging.Data.Controllers.Interfaces;
using T2.Logging.Data.Entities.Interfaces;
using T2.Logging.Business.Entities.Interfaces;
using T2.Logging.Business.Entities;
using T2.Logging.Business.Builders;
using T2.Logging.Business.Directors.Interface;
using T2.Logging.Business.Entities.Search.Interfaces;

//--Change Management Control - Application Director  --**********************
//--Created By: trooks
//--Description: Application Director Class
//--Created Date: 03/07/2013 10:05:31
//--*************************************************************

namespace T2.Logging.Business.Directors
{
	public partial class Application_Director_biz : IApplication_director_biz
	{
		
		public List<IApplication_biz> Construct (IApplication_biz _param, bool BuildUp, bool BuildDown)
		{
			Application_Builder build = new Application_Builder();
			List<IApplication_biz> retVal = build.BuildParts(_param);
			foreach(IApplication_biz item in retVal)
			{
				item.Tenant = BuildTenant(item, BuildUp, false);
				item.Log_List = BuildLogList(item, false, BuildDown);
		}
			return retVal;
		}
		public List<IApplication_biz> Construct (IApplicationSearch_biz _param, bool BuildUp, bool BuildDown)
		{
			Application_Builder build = new Application_Builder();
			List<IApplication_biz> retVal = build.BuildParts(_param);
			foreach(IApplication_biz item in retVal)
			{
				item.Tenant = BuildTenant(item, BuildUp, false);
				item.Log_List = BuildLogList(item, false, BuildDown);
		}
			return retVal;
		}
		private ITenant_biz BuildTenant(IApplication_biz _param, bool BuildUp, bool BuildDown)
		{
			ITenant_biz retVal = new Tenant_biz();
			if(BuildUp)
			{
			ITenant_biz TenantParam = new Tenant_biz();
			TenantParam.Action = "GetOne";
			TenantParam.TenantID = _param.TenantID;
			Tenant_Builder builder = new Tenant_Builder();
			retVal = builder.BuildParts(TenantParam).First();
			}
			return retVal;
		}
		private List<ILog_biz> BuildLogList(IApplication_biz _param, bool BuildUp, bool BuildDown)
		{
			List<ILog_biz> retVal = new List<ILog_biz>();
			if(BuildDown)
			{
			ILog_biz LogParam = new Log_biz();
			LogParam.Action ="Application_Log_ByParent";
			LogParam.PageNumber = 1;
			LogParam.PageSize = 100;
			LogParam.SortType = "asc";
			LogParam.SortColumn = "LogID";
			LogParam.ApplicationID = _param.ApplicationID;
			Log_Builder builder = new Log_Builder();
			retVal = builder.BuildParts(LogParam);
			}
			return retVal;
		}
	}
}